package demo4;
class A implements Cloneable{
    int age ;

    public A(int age) {
        this.age = age;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Student implements Cloneable{
    int age ;
    String name ;
    A a ;

    public Student(int age, String name, A a) {
        this.age = age;
        this.name = name;
        this.a = a;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student tmp = (Student) super.clone();
        tmp.a = (A)tmp.a.clone() ;
        return tmp ;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", a=" + a.age +
                '}';
    }
}

public class Test4 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student s1 = new Student(13,"张三" ,new A(1) ) ;
        Student s2 = (Student) s1.clone() ;
        System.out.println(s1);
        System.out.println(s2);
        System.out.println("==============");
        s1.a.age = 3 ;
        System.out.println(s1);
        System.out.println(s2);
    }

}
